#!/bin/bash
# Linux脚本：批量重建Conda环境

echo "批量重建Conda环境"
echo "==================="

env_dir="conda_environments"

if [ ! -d "$env_dir" ]; then
    echo "错误: 找不到环境目录 $env_dir"
    exit 1
fi

echo "发现以下环境文件:"
for file in "$env_dir"/*_compatible.yml; do
    basename=$(basename "$file" _compatible.yml)
    echo "- $basename"
done

echo
read -p "是否继续重建这些环境? (y/n): " confirm

if [ "$confirm" != "y" ]; then
    echo "操作已取消"
    exit 0
fi

for file in "$env_dir"/*_compatible.yml; do
    basename=$(basename "$file" _compatible.yml)
    echo "正在重建环境: $basename"
    conda env create -f "$file"
    
    if [ $? -ne 0 ]; then
        echo "警告: 环境 $basename 创建失败"
    else
        echo "环境 $basename 创建成功"
    fi
    echo
done

echo "所有环境重建完成" 